<style>
    .product_img img {
        border:solid 3px #fff;
        margin-right:5px;
    }
    .product_img img.hover {
        border-color:#ff8800;
    }
    .product_img img.current {
        border-color:#df0001;
    }
</style>
<div class="container bm-page">
    <div class="col-md-8">
        <div class="bm-form-container" >
            <div class="crumbs-box">
                <?php if ($special_model && $special_model->id != 1): ?>
                    <?php
                    if (stripos($special_model->bm_img, 'http://') !== false) {
                        $bm_img = $special_model->bm_img;
                    } else {
                        $bm_img = Yii::app()->theme->baseUrl . $special_model->bm_img;
                    }
                    ?>        
                    <img alt="" src="<?php echo $bm_img; ?>">
                    <span><?php echo $special_model->name; ?>报名</span>
                <?php else: ?>
                    <img alt="" src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/special/bm_put.png">
                    <span>商品报名</span>
                <?php endif; ?>
                <div class="clearfix"></div>
            </div>
            <!--
            <div class="crumbs-box">
                    <div class="crumbs bm-spt"></div>
            </div>
            -->
            <div class="form-box">
                <!--
                <div class="bm-tabs"> 
                    <a href="<?php echo YzwController::U('bm') ?>" class="pull-left btn bm-btn active"><i class="bm-spt"></i>天猫、淘宝商品报名</a>
                    <a href="<?php echo $this->createUrl('/front/blacklist/index'); ?>" class="pull-right black_btn" target="_blank">
                        <img alt="" src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/blacklist.png">
                    </</div>
                -->           <form id="goodsbm" action="" method="post">
                    <table class="form">
                        <tbody>





                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'detail_url'); ?>：</td>
                                <td width="500px"><input type="text" name="detail_url" class="input input-mid" value="<?php echo $data['detail_url'] ?>" id="detail_url" placeholder="请填写商品地址，支持淘宝、天猫">
                                    <input type="button" class="get-good bm-spt" id="get_good"><div style="margin:7px 7px" class="tips_hold"id="tip_1"data-content="<div class='tip_box' >点击可快速获取所报名宝贝的基本信息,建议快速获取</div>"></div></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'goods_name'); ?>：</td>
                                <td><input type="text" class="input input-big" name="goods_name" value="<?php echo $data['goods_name'] ?>" id="goods_name" maxlength="15" placeholder="标题最短不能少于7个，最长不能大于10个"></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'product_id'); ?>：</td>
                                <td><input type="text" class="input input-big" id="product_id" value="<?php echo $data['product_id'] ?>" disabled="disabled">
                                    <input type="hidden" class="input input-big" name="product_id" value="<?php echo $data['product_id'] ?>" ></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'cat_id'); ?>：</td>
                                <td><select name="cat_id">
                                        <option value="">请选择商品分类</option>
                                        <?php echo CategoryModel::model()->htmlCategorySelectOption($data['cat_id']) ?>
                                    </select><div style="margin-top: 5px;margin-right: 330px;"class="tips_hold"id="tip_10" data-content="商品分类为必选项"></div></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'p_price'); ?>：</td>
                                <td ><input type="text" class="input input-sm" id="p_price" value="<?php echo $data['p_price'] ?>" disabled="disabled"><div style="margin-top: 5px;margin-right: 385px;" class="tips_hold"id="tip_2" data-content="宝贝原价由系统自动获取，报名时不能修改宝贝原价"></div><input type="hidden" class="input input-sm" name="p_price" value="<?php echo $data['p_price'] ?>">
                                </td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'promo_price'); ?>：</td>
                                <td><input type="text" class="input input-sm" name="promo_price" id="promo_price" value="<?php echo $data['promo_price'] ?>">
                                    <div style="margin-top: 5px;margin-right: 385px;"class="tips_hold"id="tip_3" data-content="活动价格最好设置为可接受最低价格,报名成功率将大大提升"></div></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'sales'); ?>：</td>
                                <td><input type="text" class="input input-sm" name="sales" id="sales"  value="<?php echo $data['sales'] ?>">
                                    <div style="margin-top: 5px;margin-right: 385px;"class="tips_hold"id="tip_9" data-content="商品销量需为10件以上"></div></td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'product_img'); ?>：</td>
                                <td><input type="text" class="input input-big" name="product_img" id="product_img"  placeholder="http://"   value="<?php echo $data['product_img'] ?>">
                                    <div class="trip">*图片规定尺寸大小300*300，图片使用清新背景图，模特浅底图，除品牌logo以外不能有其他字眼，请按要求来，否则不予通过。</div></td>
                            </tr>
                            <tr>
                                <td class="title"></td>
                                <td>
                                    <div class="product_img">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="title"><?php echo CHtml::activeLabel($model, 'goods_brief'); ?>：</td>
                                <td><textarea name="goods_brief" style=" width:483px; height:100px;" placeholder="商品简介不能少于25个字"><?php echo $data['goods_brief'] ?></textarea></td>
                            </tr>
                            <tr>
                                <td class="title"></td>
                                <td>
                                    <input type="hidden" name="state" value="<?php echo $data['state'] ?>" id="state">
                                    <input type="hidden" name="city" value="<?php echo $data['city'] ?>" id="city">
                                    <input type="hidden" name="brand_id" value="<?php echo $data['brand_id'] ? $data['brand_id'] : 0 ?>" id="brand_id">
                                    <input type="hidden" name="commission_rate" id="commission_rate" value="<?php echo $data['commission_rate'] ? $data['commission_rate'] : 0 ?>">
                                    <input type="hidden" name="listorder" value="<?php echo $data['listorder'] ? $data['listorder'] : 100 ?>">
                                    <input type="hidden" name="nick" id="nick" value="<?php echo $data['nick'] ?>">
                                    <input type="hidden" name="level" id="level" value="<?php echo $data['level'] ? $data['level'] : 1 ?>">
                                    <input type="hidden" name="item_type" id="item_type" value="<?php echo $data['item_type'] ? $data['item_type'] : 0 ?>">
                                    <input type="hidden" id="credit_score" value="0">
                                    <input type="hidden" id="seller_credit_score" value="6">
                                    <input class="bm-btn bm-spt" type="submit" value="">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
                <div class="bottom"> 已经有报名的商品，<a href="<?php echo YzwController::U('user/goodsbm/goods') ?>">点击查询报名情况</a>! </div>
            </div>
        </div>
    </div>
    <?php include $this->getViewFile('/goodsbm/statement'); ?>
    <div class="clear"></div>
    <?php include $this->getViewFile('/lib/login_and_reg'); ?>
</div>
<?php include $this->getViewFile('/goodsbm/container'); ?>
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/ajaxForm.js"></script>
<link rel="stylesheet" href="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/css/ui-dialog.css">
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/js/dialog-min.js"></script>
<script>
    var tips = dialog();
//防止一次提交多条
    var locking = false;
    function product_img() {
        $('div.product_img img').click(function() {
            $('div.product_img img').removeClass('current');
            $(this).addClass('current');
            $('#product_img').val(this.src);
        });
    }

    function getInfo() {
        var product_id = $('input[name="detail_url"]').val();
        if (product_id == '') {
            return false;
        }
        tips = dialog({
            fixed: true,
            title: '获取商品信息中...'
        }).show();
        $.getJSON('<?php echo YzwController::U('iteminfo') ?>', {product_id: product_id}, function(data) {
            tips.close();
            if (data.status) {
                $('#detail_url').val(data.detail_url);
                $('#goods_name').val(data.title);
                //原价
                $('#p_price').val(data.p_price);
                $('input[name="p_price"]').val(data.p_price);
                //活动价格
                $('#promo_price').val(data.promo_price);
                //商品ID
                $('#product_id').val(data.product_id);
                $('input[name="product_id"]').val(data.product_id);
                //旺旺
                $('input[name="nick"]').val(data.nick);
                //店铺类型
                $('input[name="item_type"]').val(data.item_type);
                //销量
                $('#sales').val(data.sales);
                //店铺等级
                $('#credit_score').val(data.credit_score);
                //图片
                var imgstr = '';
                if (data.images) {
                    $.each(data.images, function(i, v) {
                        if (i == 0) {
                            $('#product_img').val(v);
                            imgstr += '<img class="current" width="160" height="160" src=' + v + ' />';
                        } else {
                            imgstr += '<img  width="160" height="160"  src=' + v + ' />';
                        }
                    });
                    $('div.product_img').html(imgstr);
                    product_img();
                }
            } else {
                if (data.info) {
                    $('input[name="detail_url"]').val('');
                    alert(data.info);
                }
            }
        });
    }

//登录
    function login() {
        $('div.login_reg_page').show();
        $('#login-form').ajaxForm({
            dataType: 'json',
            url: '<?php echo YzwController::U('login') ?>',
            success: function(data) {
                if (data.status) {
                    $('#login-form').clearForm();
                    $('div.login_reg_page').hide();
                    $('#goodsbm').submit();
                } else {
                    var d = dialog({
                        title: '提示',
                        content: data.info,
                        cancel: false,
                        okValue: '确定',
                        ok: function() {
                        }
                    });
                    d.show();
                }
            }
        });
        $('#login-regmobile').ajaxForm({
            dataType: 'json',
            success: function(data) {
                if (data.status) {
                    $('#login-form').clearForm();
                    $('div.login_reg_page').hide();
                    $('#goodsbm').submit();
                } else {
                    var d = dialog({
                        title: '提示',
                        content: data.info,
                        cancel: false,
                        okValue: '确定',
                        ok: function() {
                        }
                    });
                    d.show();
                }
            }
        });
    }

    $(function() {
        $('#goodsbm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function(data, obj, es) {
                /*            if (locking) {
                 alert('服务器已经在提交中，等待服务器处理结果，请稍后！');
                 return false;
                 }*/
                //图片大小
                var image = new Image();
                if ($('#product_img').val() == '') {
                    alert('商品图片不能为空！');
                    return false;
                }
                image.src = $('#product_img').val();
                var height = image.height;
                var width = image.width;
                if (height / width < 0.95) {
                    alert('图片的尺寸不符合，请使用正方形图片！');
                    return false;
                }
                tips = dialog({
                    fixed: true,
                    title: '提交中...',
                    cancelDisplay: false
                }).showModal();
                locking = true;
                return true;
            },
            success: function(data) {
                locking = false;
                if (data.info == 'not_logged') {
                    tips.close();
                    login();
                    return true;
                }
                tips.title('系统提示');
                tips.content(data.info);
                tips.button([{
                        value: '确定',
                        callback: function() {
                            if (data.status) {
                                $('#goodsbm').clearForm();
                                $('div.product_img').html('');
                            }
                            if (data.url) {
                                window.location.href = data.url;
                            }
                            return true;
                        },
                        autofocus: true
                    }]);
            }
        });
        $('#get_good').click(function() {
            //getInfo();
        });
        $('input[name="detail_url"]').change(function() {
            getInfo();
        });
    });
</script>